package com.foreknow.homework;

import java.util.ArrayList;
import java.util.List;

public class Student {
    private String name;
    private int id;
    private double grade;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getGrade() {
        return grade;
    }

    public void setGrade(double grade) {
        this.grade = grade;
    }

    public Student(){

    }

    public Student[] stu(){
        Student[] stu=new Student[3];
        Student s1 = new Student();
        s1.setId(1);
        s1.setName("张三");
        s1.setGrade(96);
        Student s2 = new Student();
        s2.setId(2);
        s2.setName("李四");
        s2.setGrade(82);
        Student s3 = new Student();
        s3.setId(3);
        s3.setName("王五");
        s3.setGrade(87);
        stu[0]=s1;
        stu[1]=s2;
        stu[2]=s3;
        return stu;
    }

    public void arr(Student[] grad){
        //String[] gra=new String[3];
        for (int i=0;i<grad.length - 1;i++) {
            for(int j=0;j<grad.length-i -1;j++){
                if (grad[j].getGrade()<grad[j+1].getGrade()){
                    Student temp=grad[j];
                    grad[j]=grad[j+1];
                    grad[j+1]=temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        Student student=new Student();
        Student[] grad=student.stu();
        student.arr(grad);
        for(Student stu:grad) {
            System.out.println(stu.getId() + "  " + stu.getName() + "  " + stu.getGrade());
        }
    }
}
